from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-15 14:07:15.590267
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 15, May, 2021
Time: 14:07:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.2673
Nobs: 292.000 HQIC: -48.9466
Log likelihood: 3573.51 FPE: 3.51334e-22
AIC: -49.4005 Det(Omega_mle): 2.59479e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.365944 0.111394 3.285 0.001
L1.Burgenland 0.071784 0.058342 1.230 0.219
L1.Kärnten -0.225586 0.051951 -4.342 0.000
L1.Niederösterreich 0.100719 0.123880 0.813 0.416
L1.Oberösterreich 0.231635 0.120811 1.917 0.055
L1.Salzburg 0.283404 0.066334 4.272 0.000
L1.Steiermark 0.112128 0.084613 1.325 0.185
L1.Tirol 0.124972 0.058818 2.125 0.034
L1.Vorarlberg -0.032724 0.054120 -0.605 0.545
L1.Wien -0.025407 0.107580 -0.236 0.813
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.391853 0.128614 3.047 0.002
L1.Burgenland 0.005160 0.067361 0.077 0.939
L1.Kärnten 0.327275 0.059981 5.456 0.000
L1.Niederösterreich 0.116298 0.143030 0.813 0.416
L1.Oberösterreich -0.065155 0.139486 -0.467 0.640
L1.Salzburg 0.234626 0.076588 3.063 0.002
L1.Steiermark 0.096352 0.097693 0.986 0.324
L1.Tirol 0.132918 0.067911 1.957 0.050
L1.Vorarlberg 0.154004 0.062486 2.465 0.014
L1.Wien -0.385542 0.124211 -3.104 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.256459 0.056792 4.516 0.000
L1.Burgenland 0.107862 0.029744 3.626 0.000
L1.Kärnten -0.012830 0.026486 -0.484 0.628
L1.Niederösterreich 0.090131 0.063157 1.427 0.154
L1.Oberösterreich 0.283621 0.061592 4.605 0.000
L1.Salzburg 0.018510 0.033819 0.547 0.584
L1.Steiermark -0.000504 0.043138 -0.012 0.991
L1.Tirol 0.068921 0.029987 2.298 0.022
L1.Vorarlberg 0.077263 0.027592 2.800 0.005
L1.Wien 0.112364 0.054847 2.049 0.040
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188035 0.054143 3.473 0.001
L1.Burgenland 0.028206 0.028357 0.995 0.320
L1.Kärnten 0.009413 0.025251 0.373 0.709
L1.Niederösterreich 0.060415 0.060212 1.003 0.316
L1.Oberösterreich 0.399814 0.058720 6.809 0.000
L1.Salzburg 0.084571 0.032242 2.623 0.009
L1.Steiermark 0.131622 0.041126 3.200 0.001
L1.Tirol 0.049536 0.028589 1.733 0.083
L1.Vorarlberg 0.082838 0.026305 3.149 0.002
L1.Wien -0.035909 0.052290 -0.687 0.492
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.398727 0.106843 3.732 0.000
L1.Burgenland 0.104454 0.055959 1.867 0.062
L1.Kärnten 0.010448 0.049828 0.210 0.834
L1.Niederösterreich 0.043271 0.118818 0.364 0.716
L1.Oberösterreich 0.124497 0.115875 1.074 0.283
L1.Salzburg 0.064478 0.063624 1.013 0.311
L1.Steiermark 0.069142 0.081156 0.852 0.394
L1.Tirol 0.197289 0.056415 3.497 0.000
L1.Vorarlberg 0.041246 0.051909 0.795 0.427
L1.Wien -0.050064 0.103185 -0.485 0.628
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191412 0.083903 2.281 0.023
L1.Burgenland -0.009792 0.043944 -0.223 0.824
L1.Kärnten -0.005193 0.039129 -0.133 0.894
L1.Niederösterreich -0.006670 0.093307 -0.071 0.943
L1.Oberösterreich 0.424427 0.090995 4.664 0.000
L1.Salzburg 0.015323 0.049963 0.307 0.759
L1.Steiermark -0.023454 0.063731 -0.368 0.713
L1.Tirol 0.155375 0.044302 3.507 0.000
L1.Vorarlberg 0.060266 0.040763 1.478 0.139
L1.Wien 0.203304 0.081030 2.509 0.012
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195141 0.101776 1.917 0.055
L1.Burgenland 0.026324 0.053305 0.494 0.621
L1.Kärnten -0.072424 0.047465 -1.526 0.127
L1.Niederösterreich -0.030815 0.113183 -0.272 0.785
L1.Oberösterreich 0.007145 0.110379 0.065 0.948
L1.Salzburg 0.090396 0.060606 1.492 0.136
L1.Steiermark 0.314274 0.077307 4.065 0.000
L1.Tirol 0.456820 0.053740 8.501 0.000
L1.Vorarlberg 0.149297 0.049447 3.019 0.003
L1.Wien -0.134124 0.098291 -1.365 0.172
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186821 0.120990 1.544 0.123
L1.Burgenland 0.042853 0.063369 0.676 0.499
L1.Kärnten -0.073306 0.056426 -1.299 0.194
L1.Niederösterreich 0.115458 0.134552 0.858 0.391
L1.Oberösterreich 0.014291 0.131218 0.109 0.913
L1.Salzburg 0.197300 0.072048 2.738 0.006
L1.Steiermark 0.137002 0.091902 1.491 0.136
L1.Tirol 0.050952 0.063886 0.798 0.425
L1.Vorarlberg 0.109279 0.058782 1.859 0.063
L1.Wien 0.226566 0.116848 1.939 0.053
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.475431 0.067787 7.014 0.000
L1.Burgenland -0.010375 0.035503 -0.292 0.770
L1.Kärnten -0.018269 0.031614 -0.578 0.563
L1.Niederösterreich 0.108812 0.075385 1.443 0.149
L1.Oberösterreich 0.310246 0.073517 4.220 0.000
L1.Salzburg 0.026420 0.040366 0.655 0.513
L1.Steiermark -0.044164 0.051490 -0.858 0.391
L1.Tirol 0.078478 0.035793 2.193 0.028
L1.Vorarlberg 0.104481 0.032934 3.172 0.002
L1.Wien -0.029301 0.065466 -0.448 0.654
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.162351 0.083977 0.172548 0.225047 0.075472 0.084055 0.000587 0.172415
Kärnten 0.162351 1.000000 0.053965 0.216376 0.190670 -0.062585 0.180413 0.023620 0.310734
Niederösterreich 0.083977 0.053965 1.000000 0.239145 0.097514 0.314496 0.144131 0.027561 0.311745
Oberösterreich 0.172548 0.216376 0.239145 1.000000 0.307202 0.262299 0.104895 0.061467 0.147299
Salzburg 0.225047 0.190670 0.097514 0.307202 1.000000 0.157005 0.071556 0.092680 0.037971
Steiermark 0.075472 -0.062585 0.314496 0.262299 0.157005 1.000000 0.097103 0.105021 -0.095079
Tirol 0.084055 0.180413 0.144131 0.104895 0.071556 0.097103 1.000000 0.155030 0.158322
Vorarlberg 0.000587 0.023620 0.027561 0.061467 0.092680 0.105021 0.155030 1.000000 -0.012111
Wien 0.172415 0.310734 0.311745 0.147299 0.037971 -0.095079 0.158322 -0.012111 1.000000